﻿
import Request from "../../base/request.js?t=202511041006"
import Storage from "../../base/storage.js?t=202511041006"
import { imageBaseUrl, isImageFile, downloadfun, dealTime, IgetDeptList, queryURLParams, getBrowserInfo } from "../../base/utils.js?t=202511041006"
const Composition = (proxy) => {


    const data = reactive({
        pdfOpen: false,
        pdfurl: "",
        dItem: [],
        messageTest: "",
        proxy: "",
        cIndex: 1,
        uploadLock:false,

        selectedRowKeys: [],

        deptList:[],
        tabList: [],

        areaList: [
            { label: '浦东', value: 1 },
            { label: '大场', value: 2 },
        ],

        queryParams: {
            ApplyNo: null, Time: null, Status: null, DepartmentId: null, TypeId: null, FactoryAreaId:1
        },

        Ids: [],
        plform: {

        },
        imgUrl: "",
        previewShow: false,
        uploadImg: {
            previewVisible: false,
            previewImage: "",
            previewTitle: "",
            fileList: [

            ]
        },
        cId:"",
        opType: true,
        plOpen: false,
        popShow: false,
        popType: 0,
        fileList: [
        ],
        itemRender: (data) => {
            let uid = data.file.uid
            const previewBtn = h('img', { style: 'cursor:pointer;margin:0 4px;', onclick: () => { methods.btnPreview(uid) }, src: "../Bussiness/img/svg/preview.svg", width: 20, height: 22 }, { default: () => '预览' })
            const downloadBtn = h('img', { style: 'cursor:pointer;margin:0 4px;', onclick: () => { methods.btnDownLoad(uid) }, src: "../Bussiness/img/svg/download.svg", width: 20, height: 22 }, { default: () => '下载' })
            const deleteBtn = h('img', { style: 'cursor:pointer;margin:0 4px;', onclick: () => { methods.btnDelete(uid) }, src: "../Bussiness/img/svg/delete.svg", width: 18, height: 22 }, { default: () => '删除' })
            var btns = btns = h('div', { style: "display:flex;margin-left:10px" }, {
                default: () => [
                    isImageFile(data.file.url)? previewBtn:null,
                    downloadBtn,
                    deleteBtn,
                ]
            })

            return h('div', { style: 'margin-top:10px; width:100%;align-items:center; display:flex;justify-content:space-between' }, {
                default: () => [
                    data.file.name, btns
                ]
            })

        },

    

        noticePreView: {
            title: "",
            columns: [{
                title: '序号',
                dataIndex: 'no',
                key: 'no',
                align: 'center',
                width: 80,
                customRender: ({ index }) => {
                    return (params.pagination.value.current - 1) * params.pagination.value.pageSize + index + 1
                },
            },
                {
                    title: '姓名',
                    dataIndex: 'UserName',
                    key: 'UserName',
                    align: 'center',
                    customRender: ({ record }) => {
                        return `${record.UserName}(${record.UserNo})`
                    },

                },
                {
                    title: '邮箱',
                    dataIndex: 'Email',
                    key: 'Email',
                    align: 'center',

                }],
            noticePerson: [
         
            ] ,
            cctarget: [
    
            ],

            EmailBody:""
        },
        popOkText:'汇总',

        pagination: {
            total: 0,
            current: 1,
            pageSize: 10,
            loading: true,
            showTotal: total => `总共 ${total} 项`,
            defaultPageSize: 10,
            showSizeChanger: true, // 是否显示pagesize选择
            showQuickJumper: false, // 是否显示跳转窗
        },
        deptList: [

        ],
 
        columns1: [
            {
                title: '序号',
                dataIndex: 'no',
                key: 'no',
                align: 'center',
                width: 80,
                customRender: ({ index }) => {
                    return (params.pagination.value.current - 1) * params.pagination.value.pageSize + index + 1
                },
            },

            {
                title: '申请单号',
                dataIndex: 'ApplyNo', 
                key: 'ApplyNo',
                align: 'center',

            },

            {
                title: '申请部门',
                dataIndex: 'DepartmentName',
                key: 'DepartmentName',
                align: 'center',
         
            },
            {
                title: '申请人',
                dataIndex: 'ApplyUserName',
                key: 'ApplyUserName',
                align: 'center',
                customRender: function ({record }) {



                    return `${record.ApplyUserName}(${record.ApplyUser})`
                }
            },
            {
               
                title: '申请物品',
                dataIndex: 'ApplyCount',
                key: 'ApplyCount',
                align: 'center',
                customRender: function ({ text, record }) {

                
                    let textc = h(antd.Tag, {
                        color: "#2178e9",
                        style: "cursor:pointer",
                        onMouseenter:()=> methods.IGetApplyItemsDetail(record)
                    }, { default: () => text });


                    function renderDItem() {
                        // 检查 dItem 是否为空或不是数组
                        if (!Array.isArray(params.dItem.value) || params.dItem.value.length === 0) {
                            return h('div', {}, '加载中...');
                        }

                        // 遍历 dItem 数组并生成每个项的渲染内容
                        const items = params.dItem.value.map((item, index) => {
                            const productName = item.BasicInfo?.ProductName || '';
                            const attrItemList = item.AttrItemList?.map(attr => attr.AttrItemName).join('/') || '';
                            const quantity = item.Quantity || 0;
                            const unit = item.BasicInfo?.Unit || '';

                            // 拼接显示内容
                            const content = `${productName}(${attrItemList}) : ${quantity}${unit}`;

                            // 返回单个项的虚拟 DOM
                            return h('div', { key: index }, content);
                        });

                        // 将所有项包裹在一个父容器中
                        return h('div', {}, items);
                    }

             
                    let divcon = renderDItem()
           
                 
                    return h(antd.Popover, {
                        title: '物品详情',
                        content: divcon,
                        placement:"right"

                    }, () => [textc]);
                }
            },
            {
             
                title: '申请日期', 
                dataIndex: 'ApplyDate',
                key: 'ApplyDate',
                align: 'center',
                customRender: function ({ text }) {
                    return dealTime(text, 'YYYY-MM-DD HH:mm')
                }
            },

            {

                title: '厂区',
                dataIndex: 'FactoryAreaName',
                key: 'FactoryAreaName',
                align: 'center',
            },
            
            {
            
                title: '状态',
                dataIndex: 'StatusName',
                key: 'StatusName',
                align: 'center',
                customRender: function ({ text, record }) {



                    let steps = h(antd.Steps, {
                        type: "inline",
                        current: params.StatusList.value.findIndex(e => e.StatusName == record.StatusName),
                        items: params.StatusList.value.map(e => {

                            return {
                                key: e.StatusName,
                                title: e.StatusName,
                                description: e.StatusName
                            }
                        }),
                    }, { default: () => text });
                    let textc = h(antd.Tag, {
                        color: text == '暂存' ? "#d8d8d8" : "#2178e9",
                        style:'cursor:pointer'
                    }, { default: () => text });

                    return h(antd.Popover, {
                        title: '当前节点',
                        content: steps,
                    }, () => [textc]);








               
                }



            },
            {
                title: '操作',
                key: 'action',
                align: 'center',
                customRender: function ({ record }) {
               
                    let noticeBtn = h(antd.Button, {
                        style: '',
                        type: "link",
                        onClick: () => methods.handleNotice(record.Id)
                    }, { default: () => '通知' })

                    let getBtn = h(antd.Button, {
                        style: '',
                        type: "link",
                        onClick: () => methods.handleReceive(record)
                        
                    }, { default: () => '领取' })


                    let sendBtn = h(antd.Button, {
                        style: '',
                        type: "link",
                        onClick: () => methods.handleSend(record)

                    }, { default: () => '分发' })


                    let checkBtn = h(antd.Button, {
                      
                        type: "link",

                        onClick: () => {
                            methods.handleCheck(record.Id)
                        }
                    }, { default: () => '审核' })




                    let approvalBtn = h(antd.Button, {
                        type: "link",
                        onClick: () => {
                            methods.handleApproval(record.Id)
                        }
                    }, { default: () => '审批' })


                    let detailBtn = h(antd.Button, {
                        type: "link",
                        onClick: () => {
                            methods.handleDetail(record.Id)
                        }
                    }, { default: () => '详情' })
                    let editBtn = h(antd.Button, {
                        type: "link",
                        onClick: () => {
                            methods.handleEdit(record.Id, 1)
                        }
                    }, { default: () => '编辑' })


                    let WithDrawBtn = h(antd.Button, {
                        type: "link",
              
                    }, { default: () => '撤回' })

                    let DeleteBtn = h(antd.Button, {
                        type: "link",
                        danger:true
                    }, { default: () => '删除' })

                    const fWithDrawBtn = h(antd.Popconfirm, {
                        title: "确定撤回此数据？",
                        onConfirm: () => methods.handleWithdraw(record.Id)

                    }, { default: () => WithDrawBtn })


                    const fDeleteBtn = h(antd.Popconfirm, {
                        title: `提示：部门【${record.DepartmentName}】，删除后将无法恢复，请您确认。`,
                        onConfirm: () => methods.handleDelete(record.Id)

                    }, { default: () => DeleteBtn })

                    return h('div', {
                    },
                        { default: () => [record.IsWithdraw ? fWithDrawBtn : null, record.IsEdit ? editBtn : null, record.IsDistribute ? sendBtn : null, record.Status == 1 && record.IsShowApprove ? checkBtn : null, record.Status == 2 && record.IsShowApprove ? approvalBtn : null, record.IsShowNofication ? noticeBtn : null, record.IsReceive ? getBtn : null, record.IsEdit ? fDeleteBtn : null,  detailBtn] }
                    );
              
                }
            },
        ],
  

        hzColumns: [{
            title: '序号',
            dataIndex: 'no',
            key: 'no',
            align: 'center',
            width: 80,
            customRender: ({ index }) => {
                return (params.pagination.value.current - 1) * params.pagination.value.pageSize + index + 1
            },
        },
            {
                title: '劳防用品',
                dataIndex: 'BasicName',
                key: 'BasicName',
                align: 'center',

            },
            {
             
                title: '单位',
                dataIndex: 'Unit',
                key: 'Unit',
                align: 'center',

            },

            {
                title: '规格',
                dataIndex: 'AttrList',
                key: 'AttrList',
                align: 'center',
                customRender: ({ text }) => {

                    //const customSort=(a, b)=> {
                    //    // 检查是否为数字
                    //    function isNumber(str) {
                    //        return /^\d+$/.test(str);
                    //    }

                    //    // 检查是否为字母
                    //    function isLetter(str) {
                    //        return /^[a-zA-Z]+$/.test(str);
                    //    }

                    //    // 检查是否为汉字
                    //    function isChinese(str) {
                    //        return /^[\u4e00-\u9fa5]+$/.test(str);
                    //    }

                    //    // 检查字符串的主要部分
                    //    function getPrimaryType(str) {
                    //        if (isNumber(str)) return 1;
                    //        if (isLetter(str)) return 2;
                    //        if (isChinese(str)) return 3;
                    //        return 4; // 混合类型
                    //    }

                    //    // 获取字符串的主要部分
                    //    function getPrimaryPart(str) {
                    //        if (isNumber(str)) return str;
                    //        if (isLetter(str)) return str.toLowerCase();
                    //        if (isChinese(str)) return str;
                    //        return str;
                    //    }

                    //    // 比较主要部分
                    //    const primaryA = getPrimaryType(a);
                    //    const primaryB = getPrimaryType(b);

                    //    if (primaryA !== primaryB) {
                    //        return primaryA - primaryB;
                    //    }

                    //    // 如果主要部分相同，比较次要部分
                    //    return getPrimaryPart(a).localeCompare(getPrimaryPart(b));
                    //}


                    return text.map(e => e.AttributeValue).join('/')
                },

            },
  
            {
                title: '数量',
                dataIndex: 'Quantity',
                key: 'Quantity',
                align: 'center',

            },

            {
                title: '各部门申请详情',
                dataIndex: 'Departments',
                key: 'Departments',
                align: 'center',
                customRender: function ({ text, record, index, column }) {

                    let textc = h(antd.Tag, {
                        color: "#2178e9",
                        style: "cursor:pointer"

                    }, { default: () => text.length });
                    return h(antd.Popover, {
                        title: '部门申请详情',
                        content: text.map(e => `${e.DepartmentName}:${e.Count}${record.Unit}\n`).join(`  |  `)
                    }, () => [textc]);

        

                    //return textc
                }

            } ],
        sumColumns: [{
            title: '序号',
            dataIndex: 'no',
            key: 'no',
            align: 'center',
            width: 80,
            customRender: ({ index }) => {
                return (params.pagination.value.current - 1) * params.pagination.value.pageSize + index + 1
            },
        },

            {
                title: '申请单号',
                dataIndex: 'ApplyNo',
                key: 'ApplyNo',
                align: 'center',

            },

            {
                title: '申请部门',
                dataIndex: 'DepartmentName',
                key: 'DepartmentName',
                align: 'center',

            },
            {
                title: '申请人',
                dataIndex: 'ApplyUserName',
                key: 'ApplyUserName',
                align: 'center',
                customRender: function ({ text, record, index, column }) {

            

                    return `${record.ApplyUserName}(${record.ApplyUser})`
                }
            },
            {

                title: '申请物品',
                dataIndex: 'ApplyCount',
                key: 'ApplyCount',
                align: 'center',
                customRender: function ({ text, record }) {


                    let textc = h(antd.Tag, {
                        color: "#2178e9",
                        style: "cursor:pointer",
                        onMouseenter: () => methods.IGetApplyItemsDetail(record)
                    }, { default: () => text });


                    function renderDItem() {
                        // 检查 dItem 是否为空或不是数组
                        if (!Array.isArray(params.dItem.value) || params.dItem.value.length === 0) {
                            return h('div', {}, '加载中...');
                        }

                        // 遍历 dItem 数组并生成每个项的渲染内容
                        const items = params.dItem.value.map((item, index) => {
                            const productName = item.BasicInfo?.ProductName || '';
                            const attrItemList = item.AttrItemList?.map(attr => attr.AttrItemName).join('/') || '';
                            const quantity = item.Quantity || 0;
                            const unit = item.BasicInfo?.Unit || '';

                            // 拼接显示内容
                            const content = `${productName}(${attrItemList}) : ${quantity}${unit}`;

                            // 返回单个项的虚拟 DOM
                            return h('div', { key: index }, content);
                        });

                        // 将所有项包裹在一个父容器中
                        return h('div', {}, items);
                    }


                    let divcon = renderDItem()


                    return h(antd.Popover, {
                        title: '物品详情',
                        content: divcon,
                        placement: "right"

                    }, () => [textc]);
                }
            },
            {

                title: '申请日期',
                dataIndex: 'ApplyDate',
                key: 'ApplyDate',
                align: 'center',
                customRender: function ({ text }) {
                    return dealTime(text, 'YYYY-MM-DD HH:mm')
                }
            }, {

                title: '厂区',
                dataIndex: 'FactoryAreaName',
                key: 'FactoryAreaName',
                align: 'center',
            },],
        sumDataSource: [],

        sendColumns: [{
            title: '序号',
            dataIndex: 'no',
            key: 'no',
            align: 'center',
            width: 80,
            customRender: ({ index }) => {
                return index+1
            },
        },
       
        {
            title: '劳防用品',
            dataIndex: 'BasicInfo',
            key: 'BasicInfo',
            align: 'center',
            customRender: ({ text }) => {

                let textc = h('div', {

                    style: "cursor:pointer;width:100%;display:flex;flex-direction: column;align-items: center;"

                }, {
                    default: () => text.map(e => {
                        return h('div', {
                            style:"width:300px;margin-top:4px;"
                        }, {
                            default: () => e
                        })
            
                    })
                });

                  return textc
            },
        },

        {
            title: '领取人',
            dataIndex: 'EmpInfo',
            key: 'EmpInfo',
            align: 'center',

        },
        {
            title: '领取日期',
            dataIndex: 'ApplyUserName',
            key: 'ApplyUserName',
            align: 'center',
        },
        {

            title: '签名栏',
            dataIndex: 'ApplyCount',
            key: 'ApplyCount',
            align: 'center',

        }],
        sendDataSource: [],
         hzDataSource: [],
        dataSource1: [],
        eDetailinfo: {

        },
        recordInfo: {},
        StatusList: [],
        sumInfo: ""
    })
    let params = toRefs(data)
    const methods = {
        sChange: (e) => {
            Storage.set('FactoryAreaId', e)
            params.Ids.value = []
        },
        tchange: (e) => {
  
            Storage.set('PageType', params.cIndex.value,true)
            methods.getTableList(true)

            params.queryParams.value = {
    
            }
            params.queryParams.value.FactoryAreaId = +Storage.get('FactoryAreaId') || null
            params.Ids.value = []
        },
        handleWithdraw: (id) => {


            Request({
                url: "/PPE/WithdrawPPEApply",
                method: 'post',
                data: {
                    Id: id
                }
            }).then(res => {
                methods.getTableList(true)
                params.messageTest.value.info(res.Msg);
            })
        
        },

        handleDelete: (id) => {
            Request({
                url: "/PPE/DeletePPEApply",
                method: 'post',
                data: {
                    Id: id
                }
            }).then(res => {
                params.messageTest.value.info(res.Msg);
                methods.getTableList(true)

            })
          },
        setVisible: (value) => {
            params.previewShow.value = value;
        },
        rowSelection: {
            onChange: (selectedRowKeys, selectedRows) => {
                //console.log(selectedRows, 'selectedRows')
                //params.selectedRowKeys.value = selectedRowKeys
                params.Ids.value = selectedRows
            },
            //selectedRowKeys: params.selectedRowKeys.value,
        },
        btnPreview: (e) => {
            let item = params.uploadImg.value.fileList.find(es => es.uid == e)
            item.url = item.FilePath || item.url
            if (item.url.indexOf('.pdf') != -1) {
                params.pdfurl.value = item.url
                params.pdfOpen.value = true
            } else {
                params.imgUrl.value = item.url

                methods.setVisible(true)
            }
        },
        btnDownLoad: (e) => {
            let item = params.uploadImg.value.fileList.find(es => es.uid == e)
            item.url = item.FilePath || item.url
            const { name, url } = item
            params.uploadLock.value = true
            downloadfun(name, url).then(() => {
            }).finally(() => {
                params.uploadLock.value = false
            })

         
  

        },
        btnDelete: (e) => {
            params.uploadImg.value.fileList = params.uploadImg.value.fileList.filter(es => es.uid != e)
        },
        IGetApplyItemsDetail: (record) => {
            params.dItem.value = []
            Request({
                url: "/PPE/GetApplyItemsDetail",
                method: 'post',
                data: {
                    FormId: record.Id
                }
            }).then(res => {
                params.dItem.value=res.Data
                //console.log(res,'res')
                //params.sendDataSource.value = res.Data
                //params.popShow.value = true
            })

        },
        GetStatusList: () => {
            Request({
                url: "/PPE/GetStatusList",
                method: 'post',
                data: {
                    TypeId: params.cIndex.value
                }
            }).then(res => {
                params.StatusList.value = res.Data

            })
        },
        handleSend: (record) => {

            params.uploadImg.value = {
                previewVisible: false,
                previewImage: "",
                previewTitle: "",
                fileList: [

                ]
            }
            params.recordInfo.value = record
            params.popType.value = 4
            Request({
                url: "/PPE/GetEmpApplyReportData",
                method: 'post',
                data: {
                    FormId: record.Id
                }
            }).then(res => {

                params.sendDataSource.value = res.Data
                params.popShow.value = true
            })
      
        },

        handleReceive: (record) => {
            params.uploadImg.value = {
                previewVisible: false,
                previewImage: "",
                previewTitle: "",
                fileList: [

                ]
            }
            params.recordInfo.value = record
            params.popType.value = 3
            params.popShow.value = true



        },

        handleChange: (info) => {
    
            if (!params.uploadLock.value) {
                params.uploadLock.value = true

                let formData = new FormData();
                formData.append('nfile', info.file.originFileObj)
                formData.append('uid', info.file.originFileObj.uid)
                Request({
                    url: "/download/uploadfile?Path=PPE/Apply",
                    method: 'post',
                    data: formData
                }).then(res => {
                    params.uploadLock.value = false
                    let item = params.uploadImg.value.fileList.find(e => e.uid == res.Data[0].uid)
                    item.url = imageBaseUrl + res.Data[0].FilePath.split('../..')[1]
                    item.FileId = res.Data[0].FileId
                    item.FileName = res.Data[0].FileName
                    item.name = res.Data[0].FileName
                })
            }

      

        },

        handleNotice: (id) => {
            //2  popOkText  确定  popTitle 通知预览
            methods.getNoticeDetail(id).then(res => {
                params.popType.value = 2
                //params.popOkText.value = '确定'
                params.cId.value = id
                //params.popTitle.value = '通知预览'
                params.popShow.value = true

            })
        },
        handleExport: () => {

            Request({
                url: "/PPE/ExportTotalApplyList",
                method: 'post',
                data: {
                    IdList: params.Ids.value.map(e => e.Id)
                }
            }).then(res => {
                if (res.Code == '-100') {
                    return
                 }
           
                downloadfun(res.Data.split('/')[res.Data.split('/').length - 1], res.Data)
            })

            ///PPE/ExportTotalApplyList
        },

        getNoticeDetail: (id) => {

            return new Promise((resolve, reject) => {

                Request({
                    url: "/PPE/GetEmailDetail",
                    method: 'post',
                    params: {
                        FormId: id
                    },

                }).then(res => {
                    resolve(1)
                    console.log(res.Data)
                    params.eDetailinfo.value = res.Data


                    params.noticePreView.value.title = res.Data.Subject
                    params.noticePreView.value.noticePerson = res.Data.To
                    params.noticePreView.value.cctarget = res.Data.Cc
                    params.noticePreView.value.EmailBody = res.Data.EmailBody
                }).catch(err => {

                    reject(err)
                })

            })

        },

        handleSum: (ids) => {
            params.pagination.value.loading = true
            Request({
                url: "/PPE/GetTotalApplyList",
                method: 'post',
                data: {
                    IdList: ids
                }
            }).then(res => {
   

                params.hzDataSource.value = res.Data
                params.pagination.value.loading = false

            })



        },

        handlePopClose: () => {
   
            //if (params.popType.value == 0) {
            //    params.sumDataSource.value=[]
            //}
        },
        handlePopOk: () => {
            if (params.popType.value == 0) {

                methods.handleSum(params.Ids.value.map(e => e.Id))
                params.sumInfo.value = params.Ids.value.map(e => e.ApplyNo).join(`  |  `)
                params.popType.value = 1
                //params.popTitle.value ='汇总单信息'
                //params.popOkText.value = '导出'





            } else if (params.popType.value == 1) {


                params.popType.value = 0
                //params.popOkText.value = '汇总'
                //params.popTitle.value = '选择汇总申请单信息'
                params.popShow.value = false
                methods.handleExport()
            }
            else if (params.popType.value == 2) {
             params.pagination.value.loading=true
                Request({
                    url: "/PPE/SendNofication",
                    method: 'post',
                    data: {
                        FormId: params.cId.value
                    }
                }).then(res => {
                    params.messageTest.value.info(res.Msg);
                    methods.getTableList(true)
                    params.pagination.value.loading = false
                })



                params.popShow.value = false
            } else if (params.popType.value == 3) {
                let subFileList = params.uploadImg.value.fileList.map(e => e.FileId)
                if (subFileList.length == 0) {
                    return params.messageTest.value.info('请先上传文件');
                }

                const { Status, Id } = params.recordInfo.value
                params.pagination.value.loading = true
                Request({
                    url: "/PPE/PPEReceive",
                    method: 'post',
                    data: {
                        Status: Status,
                        FormId: Id,
                        FileList: subFileList
                    }
                }).then(res => {
                    params.messageTest.value.info(res.Msg);
                    methods.getTableList(true)
                    params.pagination.value.loading = false

                })
               
            } else if (params.popType.value == 4) {
                let subFileList = params.uploadImg.value.fileList.map(e => e.FileId)
                if (subFileList.length == 0) {
                    return params.messageTest.value.info('请先上传文件');
                }

                const { Status, Id } = params.recordInfo.value




                Request({
                    url: "/PPE/PPEReceive",
                    method: 'post',
                    data: {
                        Status: Status,
                        FormId: Id,
                        FileList: subFileList
                    }
                }).then(res => {
                    params.messageTest.value.info(res.Msg);
                    methods.getTableList(true)

                })

            }
        
        },

        downloadSend: () => {
            Request({
                url: "/PPE/ExportEmpApplyReport",
                method: 'post',
                data: {
                    FormId: params.recordInfo.value.Id
                }
            }).then(res => {
                //console.log(res,'res')

                downloadfun(res.Data.split('/')[res.Data.split('/').length - 1], res.Data)
            })
            ///PPE/

             //downloadfun('人员申请模板', '../File/Templete/PPE/劳防用品申请人员导入模板.xls')
        },
        handleSumInfo: () => {
            params.popType.value = 0
            params.popShow.value = true
            methods.getSumTableList(true)
        },

        plSubmit: (status) => {
            params.opType.value = status
            params.plOpen.value = true

        },
    
        filterOption: (val, type) => {
            return `${type.label}`.includes(`${val || ''}`)
        },

        //handleDelete: (id) => {
        //    Request({
        //        url: "/performance/DeleteMonthReport",
        //        method: 'post',
        //        params: {
        //            FormId: id
        //        },

        //    }).then(res => {
        //        params.messageTest.value.info(res.Msg);
        //        methods.getTableList(true)

        //    })
        //},

        handleEdit: (id, status = 1) => {
            //0 详情 1编辑 2 审核 3审批
            window.location.href = `/PPE/AddSupplyRequestDetail?status=${status}&id=${id}&TypeId=${params.cIndex.value}`
        },

        handleTableChange: (page) => {
            const { current, pageSize } = page
            params.pagination.value.current = current;
            params.pagination.value.pageSize = pageSize;
            methods.getTableList()
        },



        handleApproval: (id, status = 3) => {
            //0 详情 1编辑 2 审核 3审批
            window.location.href = `/PPE/AddSupplyRequestDetail?status=${status}&id=${id}&TypeId=${params.cIndex.value}`
        },
        handleCheck: (id, status = 2) => {
            //0 详情 1编辑 2 审核 3审批
            window.location.href = `/PPE/AddSupplyRequestDetail?status=${status}&id=${id}&TypeId=${params.cIndex.value}`
        },
        handleDetail: (id, status = 0) => {

    
            //0 详情 1编辑 2 审核 3审批
            window.location.href = `/PPE/AddSupplyRequestDetail?status=${status}&id=${id}&TypeId=${params.cIndex.value}`
        },

        getTableList: async (isRresh) => {
            params.queryParams.value.StartTime = params.queryParams.value.Time && params.queryParams.value.Time[0] && dayjs(params.queryParams.value.Time[0]).format('YYYY-MM-DD HH:mm:ss')
            params.queryParams.value.EndTime = params.queryParams.value.Time && params.queryParams.value.Time[1] && dayjs(params.queryParams.value.Time[1]).format('YYYY-MM-DD HH:mm:ss')
            params.queryParams.value.TypeId = params.cIndex.value
            console.log(params.queryParams.value,' params.queryParams.value.')
            if (isRresh) {
                params.pagination.value.current = 1
            }
            params.pagination.value.loading = true


            Request({
                url: "/PPE/GetPPEApplyPageList",
                method: 'post',
                params: {
                    page: params.pagination.value.current,
                    pageSize: params.pagination.value.pageSize,
                },
                data: params.queryParams.value,
            }).then(res => {
                params.dataSource1.value = res.Data.Data
                params.pagination.value.total = res.Data.TotalItemCount
                params.pagination.value.loading = false
                params.popShow.value = false
            })

        },
        getSumTableList: async (isRresh) => {
            params.sumDataSource.value = params.Ids.value
        },
        GetEuqTypeList: () => {
            return new Promise((resolve, rej) => {
                Request({
                    url: "/PPE/GetEuqTypeList",
                    method: 'post',

                }).then(res => {
                    params.tabList.value = res.Data.map(e => {
                        return {
                            label: e.TypeName,
                            value: e.Id
                        }
                    })
                    let urlParams = queryURLParams()
                    params.cIndex.value = +Storage.get('PageType',true) || +urlParams.TypeId || +params.tabList.value[0].value
     
                    methods.tchange()
                    resolve(1)

                }).catch(err => {
                    rej(0)
                })


            })
      
        },
        getDeptList: async () => {
            params.deptList.value = await IgetDeptList(Request)
          
        },
        addRequest:() => {
            window.location.href = `/PPE/AddSupplyRequest?type=${params.cIndex.value}`
        },
        init: () => {
             getBrowserInfo().catch(err => { console.log(err) })
            if (proxy) {
                params.proxy.value = proxy
            }
       
            const { message } = antd
            params.messageTest.value = message
            params.messageTest.value.config({
                top: `10vh`,
                duration: 7,
                maxCount: 1,
                rtl: true,
            });

            params.queryParams.value.FactoryAreaId = +Storage.get('FactoryAreaId') || null
            setTimeout(() => {
                let info = Storage.get('AccountInfo', true)
                Request({
                    url: "/account/createjwttoken",
                    method: 'post',
                    data: {
                        "userName": info && info.UserNo
                    }
                }).then(async (res) => {
                    Storage.set('token', res.Data,true)
                    methods.getDeptList()
                    methods.GetEuqTypeList().then(res => {
                        methods.GetStatusList()
                    })
                })

            },1000)
        },
    }



    const template = {
        pdfPopModel: {
            template: `
           <a-modal v-model:open="pdfOpen" width = "80%" title = "PDF预览" v-on:ok="pdfOpen=false" >
<div style='height:700px'>
                <embed id="pdfviewscreen" :src="pdfurl" type="application/pdf" width="100%" style="height:100%;" />

</div>
  
            </a-modal >
`,
            setup() {
                return {
                    ...params,
                    ...methods,
                };
            }
        },
        test: {
            template: `<div @click="add">+</div> <div>{{testnum}}</div>`,

            setup() {

                return {
                    ...params,
                    ...methods,
                };
            }

        }
    }
    return {
        ...params,
        ...methods,
        template
    }
}

export default Composition